*******************************************************************************
*** Description: 	This document provides code for reproducing the 		***
***					figures in Study 2 of the paper, "Elections Increase 	***
***					Satisfaction with Democracy," which is authored by 		***
***					Shane P. Singh and appears in Comparative Political		***
***					Studies. It also provides code for reproducing			***
***					statistics associated with claims made in the text.		***
*******************************************************************************



**************
**************
*Set the Version                                                                                                                                 
**************
**************
version 17


**************
**************
*Install Required Packages                                                                                                                 
**************
**************
ssc install coefplot
ssc install yalescheme



**************
**************
*Open the Study 2 Dataset
**************
**************
use "Study 2.dta", clear




**************
**************
*Figure 4
**************
**************
reg sat_dem_nat_change age_10 female educ_scale_0_10 income_harmonized_0_10 if voted_early~=., cl(countryandyear)
margins, post 
est store overall

reg sat_dem_nat_change i.voted_early age_10 female educ_scale_0_10 income_harmonized_0_10, cl(countryandyear)
margins, at(voted_early = (0 1)) post 
est store not_early_early


graph set window fontface "LMRoman10-Regular" 

coefplot ///
		(overall, offset(0) recast(scatter) mcolor(black) msize(medium) ciopts(lpattern(solid) lcolor(black))) ///
		(not_early_early, offset(0) recast(scatter) mcolor(black) msize(medium) ciopts(lpattern(solid) lcolor(black))) ///
	,  scheme(yale) horizontal ///
		order(_cons 1._at 2._at) ///
	coeflabels( _cons  	= 						`" "Main" "Model"  "'  ///
				1._at  	= 						`" "Not an Early" "Voter"  "'  ///
				2._at 	= 						`" "Early" "Voter"  "'  ///
										) ///
	graphregion(margin(small)) /// 
	legend(off) ///
	xlabel(-1(0.5)1, labsize(vsmall)) xscale(range(-1.1 1.1)) xtitle("Estimated Ef`=uchar(14)'fect of Elections on" "Satisfaction with Democracy", size(small) margin(top)) ///
	ylabel(, labsize(vsmall)) ///
	xline(0,   lcolor(gs10) lwidth(thin) lpattern(solid)) ///
	level(95) format(%9.1f) ysize(1.95) xsize(4) scale(2.5) ///
	graphregion(color(white) lcolor(black) lwidth(thick) margin(medsmall))



**************
**************
*Evidence for Claim Made in the Text: 
*...respondents' satisfaction increases by 0.40 units after an election is held.
*This effect is estimated with a high level of precision (two-sided p-value = 0.002). 
**************		
**************		
reg sat_dem_nat_change age_10 female educ_scale_0_10 income_harmonized_0_10 if voted_early~=., cl(countryandyear)
margins



**************
**************
*Evidence for Claim Made in the Text: 
*The effects for those who did not vote early and those who did are similar, at 0.39 and
*0.44 units, respectively (the two-sided p-values are 0.002 and 0.003).
**************		
**************	
reg sat_dem_nat_change i.voted_early age_10 female educ_scale_0_10 income_harmonized_0_10, cl(countryandyear)
margins, at(voted_early = (0 1))



**************
**************
*Figure 5
**************
**************	
reg sat_dem_nat_change i.winner_early_voting age_10 female educ_scale_0_10 income_harmonized_0_10 if voted_early==1 & winner_early_voting ~= 1 , cl(countryandyear)
margins, at(winner_early_voting = (2 3)) post 
est store winner_early_voting



graph set window fontface "LMRoman10-Regular" 

coefplot ///
		(winner_early_voting, offset(0) recast(scatter) mcolor(black) msize(medium) ciopts(lpattern(solid) lcolor(black))) ///
	,  scheme(yale) horizontal ///
		order(_cons 1._at 2._at) ///
	coeflabels( 1._at  	= 						`" "Winner" "(Pre-Election Vote)"  "'   ///
				2._at 	= 						`" "Loser" "(Pre-Election Vote)"  "' ///
									) ///
	graphregion(margin(small)) /// 
	legend(off) ///
	xlabel(-1(0.5)1, labsize(vsmall)) xscale(range(-1.1 1.1)) xtitle("Estimated Ef`=uchar(14)'fect of Elections on" "Satisfaction with Democracy", size(small) margin(top)) ///
	ylabel(, labsize(vsmall)) ///
	xline(0,   lcolor(gs10) lwidth(thin) lpattern(solid)) ///
	level(95) format(%9.1f) ysize(1.55) xsize(4) scale(3.05) ///
	graphregion(color(white) lcolor(black) lwidth(thick) margin(medsmall)) 



**************
**************
*Evidence for Claim Made in the Text: 
*The effects of elections on SWD for winners and losers are 0.54
*and 0.29 units, respectively (the two-sided p-values are 0.016 and 0.059), 
*and these estimates are not statistically different (two-sided p-value = 0.317).
**************		
**************	
reg sat_dem_nat_change i.winner_early_voting age_10 female educ_scale_0_10 income_harmonized_0_10 if voted_early==1 & winner_early_voting ~= 1 , cl(countryandyear)
margins, at(winner_early_voting = (2 3)) post
margins 
test _b[1._at] =  _b[2._at]





**************
**************
*Evidence for Claim Made in the Text: 
*A power analysis indicates that, at the five percent significance level, this analysis is powered at 73.5 percent.
**************		
**************	
reg sat_dem_nat_change i.winner_early_voting age_10 female educ_scale_0_10 income_harmonized_0_10 if voted_early==1 & winner_early_voting ~= 1 , cl(countryandyear)
margins, at(winner_early_voting = (2 3))
bysort winner_early_voting: sum sat_dem_nat_change if e(sample)
power twomeans .5407876 .2927709, n1(956) n2(912) alpha(0.05) sd1(2.25843) sd2(2.445594) onesided 




 



*       _------.
*      /  ,     \_
*    /   /  /{}\ |o\_
*   /    \  `--' /-' \* Thanks for replicating!
*  |      \      \    |
* |              |`-, |  
* /              /__/)/
*|              |
